﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Modelo;

namespace Interfaz
{
    /// <summary>
    /// Interaction logic for BuscarEmpleado.xaml
    /// </summary>
    public partial class BuscarEmpleado : Window
    {
        Persona persona;
        List<Persona> personas;
        public BuscarEmpleado(Persona persona)
        {
            InitializeComponent();
            this.persona = persona;
            personas=Procesos.ControlUsuario.obtenerEmpleados();
            dataGrid1.ItemsSource = personas ;
        }
        public void buscar()
        { 
            List<Persona> buscadas=new List<Persona>();
            foreach (Persona p in personas)
            {
                if (p.Ci.Contains(textBox1.Text) || p.Nombre.Contains(textBox2.Text) || p.Apellido.Contains(textBox3.Text))
                    buscadas.Add(p);
            }
            dataGrid1.Items.Clear();
            dataGrid1.ItemsSource = buscadas;
            dataGrid1.Items.Refresh();
        }
        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            buscar();
        }

        private void textBox2_TextChanged(object sender, TextChangedEventArgs e)
        {
            buscar();
        }

        private void dataGrid1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Persona p=dataGrid1.Items[dataGrid1.SelectedIndex] as Persona;
            persona.Ci = p.Ci;
            this.Close();
        }

        private void textBox3_TextChanged(object sender, TextChangedEventArgs e)
        {
            buscar();
        }
    }
}
